var Cache = require('ttl-cache'),
    shortId = require('shortid');

var ObjectCache = function () {
    var _cache = new Cache();

    this.push = function (obj, seconds) {
        var key;

        do {
            key = shortId.generate();
        } while (key in _cache.data);

        _cache.set(key, obj);
        _cache.ttl(key, seconds || 180);

        return key;
    };

    this.peek = function (key) {
        return _cache.get(key);
    };

    this.pop = function (key) {
        var obj = _cache.get(key);
        _cache.del(key);
        return obj;
    };
};

ObjectCache.default = new ObjectCache();

module.exports = ObjectCache;